package org.epidroid.epidroid.androsoul.ui.contactlist;

import java.util.List;

import org.epidroid.epidroid.R;
import org.epidroid.epidroid.androsoul.engine.contacts.ContactGroup;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class GroupAdapter extends ArrayAdapter<ContactGroup> implements
		OnClickListener {

	private List<ContactGroup> mItems;
	private Context mContext;
	private int _textViewRes = 0;

	public GroupAdapter(Context context, int textViewResourceId,
			List<ContactGroup> dataItems) {
		super(context, textViewResourceId, dataItems);
		this.mContext = context;
		this.mItems = dataItems;
		_textViewRes = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(_textViewRes, null);
		}
		final ContactGroup c = this.mItems.get(position);

		TextView login = (TextView) v.findViewById(R.id.list_header_title);
		int nbConnected = c.getNbConnected();
		login.setText(c.getName() + " (" + nbConnected + "/"
				+ c.getList().size() + ")");

		return (v);
	}

	@Override
	public void onClick(View v) {
	}
}
